<%@ page language="java" contentType="text/html;charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<head>
    <jsp:include page="../common/common.jsp"/>
</head>
<body class="page-header-fixed">
<jsp:include page="../common/header.jsp"/>
<div class="clearfix">
</div>
<div class="page-container">
    <div class="page-sidebar-wrapper">
        <jsp:include page="../common/menu.jsp"/>
    </div>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <form class="form-horizontal form-row-seperated" action="${path}/friendLink/saveFriendLink">
                        <div class="portlet box purple">
                            <div class="portlet-title">
                                <div class="caption">
                                    <i class="fa fa-shopping-cart"></i>友情链接信息
                                </div>
                                <div class="actions btn-set">
                                    <a href="javascript:history.go(-1);" class="btn default"><i
                                            class="fa fa-angle-left"></i> 返回</a>
                                    <a href="javascript:location.reload();" class="btn green"><i
                                            class="fa fa-reply"></i> 重置</a>
                                    <button type="button" id="btnSave" class="btn blue"><i class="fa fa-check"></i> 保存
                                    </button>
                                </div>
                            </div>
                            <div class="portlet-body">
                                <div class="tabbable">
                                    <div class="tab-content no-space">
                                        <div class="tab-pane active" id="tab_general">
                                            <div class="form-body">
                                                <!--  <div class="form-group">
                                                       <label class="col-md-2 control-label">友情链接类型:
                                                       <span class="required">*</span>
                                                       </label>
                                                       <div class="col-md-5">
                                                           <select name="type" class="form-control">
                                                                   <option value="1">文字链接</option>
                                                                   <option value="2">图片链接</option>
                                                           </select>
                                                       </div>
                                                   </div>-->
                                                <input type="hidden" name="type" value="2">

                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">网站名称:
                                                        <span class="required">*</span>
                                                    </label>

                                                    <div class="col-md-5">
                                                        <input type="text" id="name" name="name"
                                                               class="form-control measure-input"
                                                               value="${data.title}"/>
                                                    </div>
                                                    <div class="col-md-5">
                                                        &nbsp;可输入<b><span id="title_len">80</span></b> 个字符
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">网址:
                                                        <span class="required">*</span>
                                                    </label>

                                                    <div class="col-md-5">
                                                        <input type="text" id="url" name="url"
                                                               class="form-control measure-input"
                                                               value="${data.keyword}"/>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">logo地址:</label>

                                                    <div class="col-md-8">
                                                        <div class="fileinput fileinput-new" data-provides="fileinput">
                                                            <div class="fileinput-new thumbnail"
                                                                 style="width: 300px; height: 150px;">
                                                                <img src="${data.logourl}">
                                                            </div>
                                                            <div class="fileinput-preview fileinput-exists thumbnail"
                                                                 style="max-width: 300px; max-height: 150px;">
                                                            </div>
                                                            <div>
                                                                <span class="btn default btn-file">
                                                                    <span class="fileinput-new">选择图片</span>
                                                                    <span class="fileinput-exists">修改图片</span>
                                                                    <input type="file" id="file" name="file"/>
                                                                </span>
                                                                <a href="#" class="btn default fileinput-exists" data-dismiss="fileinput">移除图片</a>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">状态:
                                                        <span class="required">*</span>
                                                    </label>

                                                    <div class="col-md-5">
                                                        <select name="status" class="form-control">
                                                            <option value="0">正常</option>
                                                            <option value="1">禁用</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">失效时间:
                                                        <span class="required">*</span>
                                                    </label>

                                                    <div class="col-md-5">
                                                        <input type="text" id="efftime" name="efftime"
                                                               class="form-control" value=""/>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">描述:
                                                    </label>

                                                    <div class="col-md-8">
                                                        <textarea cols="60" id="remark" name="remark"
                                                                  rows="5">${data.context}</textarea>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">排序:
                                                    </label>

                                                    <div class="col-md-5">
                                                        <input type="text" id="sort" name="sort" class="form-control"
                                                               value="${data.originAddress}"/>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="portlet-title">
                                <div class="actions btn-set">
                                    <a href="javascript:history.go(-1);" class="btn default"><i
                                            class="fa fa-angle-left"></i> 返回</a>
                                    <a href="javascript:location.reload();" class="btn green"><i
                                            class="fa fa-reply"></i> 重置</a>
                                    <button type="button" id="btnSave" class="btn blue"><i class="fa fa-check"></i> 保存
                                    </button>
                                </div>
                            </div>
                        </div>
                        <input type="hidden" id="id" name="id" value="${data.id}">
                        <input type="hidden" id="logourl" name="logourl" value="${data.logourl}"/>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<jsp:include page="../common/footer.jsp"/>
<script type="text/javascript" src="${path}/assets/plugins/bootstrap-fileinput/bootstrap-fileinput.js"></script>
<script type="text/javascript" src="${path}/assets/scripts/biz/ajaxfileupload.js"></script>
<script>
    $(function () {
        $("button[id='btnSave']").click(function () {
            ajaxFileUpload(function () {
                App.ajax(_path + "/friendLink/saveFriendLink", $("form").serialize(), function (data) {
                    if (data.statusCode == 200) {
//                    if (confirm("新增友情链接成功，是否跳转到友情链接列表页面？"))
                        window.location.href = _path + "/friendLink/list/0";
                    } else {
                        App.bubble(500, "新增友情链接失败！");
                    }
                });
            });
        });
    });
    function ajaxFileUpload(callback) {
        if (!$("#file").val()) {
            callback();
            return;
        }
        $("#loading").ajaxStart(function () {
            $(this).show();
        }).ajaxComplete(function () {
            $(this).hide();
        });
        $.ajaxFileUpload({
            url: '${path}/conf/upload',
            secureuri: false,
            fileElementId: 'file',
            dataType: 'json',
            success: function (data, status) {
                switch (data.statusCode) {
                    case 200 :
                        $("#logourl").val(data.uri);
                        callback();
                        break;
                    case 500 :
                        alert(data.info);
                        break;
                }
            }
        });
        return false;
    }
</script>
</body>
</html>